package cn.itcast.activiti.servlet.task;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;

import cn.itcast.activiti.common.ProcessEngineUtils;

/**
 * 查询任务
 * @author Administrator
 *
 */
@WebServlet("/queryTask.action")
public class QueryTaskServlet extends HttpServlet{

	private static final long serialVersionUID = 2647155009632997137L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse respose)
			throws ServletException, IOException {
		System.out.println("123");
		//获取流程实例Id
		String piId=request.getParameter("piId");
		System.out.println(piId);
		//获取流程引擎
		ProcessEngine processEngine=ProcessEngineUtils.getProcessEngine();
		//获取任务服务
		TaskService taskServic=processEngine.getTaskService();
		//创建任务查询对象
		TaskQuery taskQuery=taskServic.createTaskQuery();
		//调用任务查询对象的方法完成查询
		List<Task> taskLists=taskQuery.processInstanceId(piId).list();
		
		request.setAttribute("taskLists", taskLists);
		request.getRequestDispatcher("/task.jsp").forward(request, respose);;
	}

}
